import React,{useEffect} from 'react'
import Head from './Head'
import './head.css'
import {checked} from './actionCreators'
import {checkno} from './actionCreators'
import {connect } from 'react-redux'
import {func} from './actionCreators'

const Checked = (props) => {
    let i=0;
    useEffect(() => {
        props.dispatch(checked());
        

    },[])
    useEffect(() => {
        
        props.dispatch(checkno());

    },[])
    
   
    return (
        <div>
            <Head/>
            <div className='title'>
                审批管理>已审批
            </div>
            <div className='checktable'>
            <table id="table" border='1' cellspacing='0'>
                    <tr>
                        <th>排序</th>
                        <th>学号</th>
                        <th>姓名</th>
                        
                        <th>预约教室</th>
                        <th>预约日期</th>
                        <th>预约时间</th>
                        <th>类型</th>
                        <th>申请原因</th>
                        <th>结果</th>
                        <th>操作</th>
                                     
                    </tr>
                    {props.checkeds.map((item)=>{
                        item.Start=item.Start+''
                        item.Endtime=item.Endtime+''
                        i++;
                        return<tr id="row">
                            <td>{i}</td>
                            <td>{item.Sno} </td>
                            <td>{item.Sname}</td>
                            <td>{item.Cno} </td>
                            <td>{item.time}</td>
                            <td >{item.Start.slice(0,item.Start.length-2)+':'+ item.Start.slice(-2)}-{item.Endtime.slice(0,item.Endtime.length-2)+':'+ item.Endtime.slice(-2)}</td>
                            <td>{item.Type} </td>
                            <td>{item.Text}</td>
                            <td>通过</td>
                            <td>
                            <button
                                onClick={(de)=>{
                                    de={type:'de',table:'Approval',Submittime:item.Submittime}
                                    props.dispatch(func(de))
                                    setTimeout(()=>{
                                        props.history.go(0);
                                        alert('删除成功');
                                    },1000)
                                    // ()=>{
                                    //     let table = document.getElementById("table");
                                    //     let row=document.getElementById("row")
                                    //     table.removeChild(row)
                                    // }
                                }}
                                >删除</button>
                            </td>  
                                                             
                        </tr>
                    })} 
                    {
                        (props.checknos? props.checknos.map((item)=>{

                            i++;
                            return<tr>
                                <td>{i}</td>
                                <td>{item.Sno} </td>
                                <td>{item.Sname}</td>
                                <td>{item.Cno} </td>
                                <td>{item.time}</td>
                                <td >{item.Start}-{item.Endtime}</td>
                                <td>{item.Type} </td>
                                <td>{item.Text}</td>
                                <td>未通过</td>
                                <td>
                            <button
                                onClick={(de)=>{
                                    de={type:'de',table:'Approval',Submittime:item.Submittime}
                                    props.dispatch(func(de))
                                    setTimeout(()=>{
                                        props.history.go(0);
                                        alert('删除成功');
                                    },1000)
                                }}
                                >删除</button>
                            </td>  
                                                                 
                            </tr>
                        }):'')
                   } 
                    
                </table>

            </div>
            
        </div>
    )
}
const mapStateToProps=(state)=>({
    checkeds:state.checked.checkeds,
    checknos:state.checkno.checknos,
    rets:state.func.rets
    
  })
export default connect(mapStateToProps)(Checked)
